class Solution {
    vector<string> res;
public:
    void dfs(string path, int n, int left, int right) {
        if (left == n && right == n) {
            res.push_back(path);
            return;
        }
        if (left < n) {
            dfs(path+"(", n, left+1, right);
        }
        if (right < n && right < left) {
            dfs(path+")", n, left, right+1);
        }
    }
    vector<string> generateParenthesis(int n) {
        dfs("", n, 0, 0);
        return res; 
    }
};